Add option "DATATYPE", which can be WAYPOINT, ROUTE or TRACK, to xcsv format.
authoroliskoli <oliskoli>
Sat, 27 Jan 2007 21:37:49 +0000 (21:37 +0000)
committeroliskoli <oliskoli>
Sat, 27 Jan 2007 21:37:49 +0000 (21:37 +0000)
csv_util.c
csv_util.h
vecs.c
xcsv.c

index ceb4c5f8ac01cf17f289c6fd9270f85d2cbb7fe3..f2e52c84b7beb1d09a4bf4547023c4864ee154ea 100644 (file)
@@ -1005,7 +1005,18 @@ xcsv_data_read(void)
     queue *elem, *tmp;
     field_map_t *fmp;
     ogue_t *ogp;
+    route_head *rte = NULL;
+    route_head *trk = NULL;
     
+    if (xcsv_file.datatype == trkdata) {
+       trk = route_head_alloc();
+       track_add_head(trk);
+    } else
+    if (xcsv_file.datatype == rtedata) {
+       rte = route_head_alloc();
+       route_add_head(rte);
+    }
+
     while ((buff = gbfgetstr(xcsv_file.xcsvfp))) {
         linecount++;
        /* Whack trailing space; leading space may matter if our field sep
@@ -1066,7 +1077,16 @@ xcsv_data_read(void)
                GPS_Math_Known_Datum_To_WGS84_M(wpt_tmp->latitude, wpt_tmp->longitude, 0.0,
                    &wpt_tmp->latitude, &wpt_tmp->longitude, &alt, xcsv_file.gps_datum);
            }
-            waypt_add(wpt_tmp);
+           switch(xcsv_file.datatype) {
+               case 0:
+               case wptdata:
+                   waypt_add(wpt_tmp); break;
+               case trkdata:
+                   track_add_wpt(trk, wpt_tmp); break;
+               case rtedata: 
+                   route_add_wpt(rte, wpt_tmp); break;
+               default: ;
+           }
         }
 
     }
@@ -1528,9 +1548,12 @@ xcsv_data_write(void)
        gbfprintf(xcsv_file.xcsvfp, "%s", xcsv_file.record_delimiter);
     }
 
-    waypt_disp_all(xcsv_waypt_pr);
-    route_disp_all(xcsv_resetpathlen,xcsv_noop,xcsv_waypt_pr);
-    track_disp_all(xcsv_resetpathlen,xcsv_noop,xcsv_waypt_pr);
+    if ((xcsv_file.datatype == 0) || (xcsv_file.datatype == wptdata))
+       waypt_disp_all(xcsv_waypt_pr);
+    if ((xcsv_file.datatype == 0) || (xcsv_file.datatype == rtedata))
+       route_disp_all(xcsv_resetpathlen,xcsv_noop,xcsv_waypt_pr);
+    if ((xcsv_file.datatype == 0) || (xcsv_file.datatype == trkdata))
+       track_disp_all(xcsv_resetpathlen,xcsv_noop,xcsv_waypt_pr);
 
     /* output epilogue lines, if any. */
     QUEUE_FOR_EACH(&xcsv_file.epilogue, elem, tmp) {
index cfb0eaaa2c283616aa7fe070f054aee1baacbff4..e8659a82b13f7f2fece8c127a4c561519bb8ff4b 100644 (file)
@@ -133,6 +133,8 @@ typedef struct {
     ff_type type;              /* format type for GUI wrappers. */
 
     int gps_datum;             /* result of GPS_Lookup_Datum_Index */
+    gpsdata_type datatype;     /* can be wptdata, rtedata or trkdata */
+                               /* ... or ZERO to keep the old behaviour */
 
 } xcsv_file_t;
 
diff --git a/vecs.c b/vecs.c
index 80dac5122adc5000360cab5a094333a27e5cff0d..45c2689b9729ed503a1d81dda7023d5acbab90b6 100644 (file)
--- a/vecs.c
+++ b/vecs.c
@@ -976,7 +976,17 @@ sort_and_unify_vecs(int *ctp)
                         */
                        svp[i]->vec->args++;
                }
-               
+               memset(&svp[i]->vec->cap, 0, sizeof(svp[i]->vec->cap));
+               switch(xcsv_file.datatype) {
+                       case 0:
+                       case wptdata:
+                               svp[i]->vec->cap[ff_cap_rw_wpt] = ff_cap_read | ff_cap_write; break;
+                       case trkdata:
+                               svp[i]->vec->cap[ff_cap_rw_trk] = ff_cap_read | ff_cap_write; break;
+                       case rtedata:
+                               svp[i]->vec->cap[ff_cap_rw_rte] = ff_cap_read | ff_cap_write; break;
+                       default: ;
+               }
                svp[i]->desc = xcsv_file.description;
                svp[i]->parent = "xcsv";
        }
diff --git a/xcsv.c b/xcsv.c
index 87cb0ead5c7a3b526f710c9a76dab625faf11d98..c3677c923376f856b4ac86965d61e13e15681bf5 100644 (file)
--- a/xcsv.c
+++ b/xcsv.c
@@ -338,6 +338,24 @@ xcsv_parse_style_line(const char *sbuff)
            is_fatal(xcsv_file.gps_datum < 0, MYNAME ": datum \"%s\" is not supported.", p);
            xfree(p);
        } else
+
+       if (ISSTOKEN(sbuff, "DATATYPE")) {
+           p = csv_stringtrim(&sbuff[8], "\"", 1);
+           if (case_ignore_strcmp(p, "TRACK") == 0) {
+               xcsv_file.datatype = trkdata;
+           }
+           else if (case_ignore_strcmp(p, "ROUTE") == 0) {
+               xcsv_file.datatype = rtedata;
+           }
+           else if (case_ignore_strcmp(p, "WAYPOINT") == 0) {
+               xcsv_file.datatype = wptdata;
+           }
+           else {
+               fatal(MYNAME ": Unknown data type \"%s\"!\n", p);
+           }
+           xfree(p);
+       
+       } else
        
        if (ISSTOKEN(sbuff, "IFIELD")) {
            key = val = pfc = NULL;
@@ -521,8 +539,10 @@ xcsv_rd_init(const char *fname)
         xcsv_read_style(styleopt);
     }
 
-    if (global_opts.masked_objective & (TRKDATAMASK|RTEDATAMASK)) {
-       warning(MYNAME " attempt to read %s as a track or route, but this module only supports waypoints on read.  Reading as waypoints instead.\n", fname);
+    if ((xcsv_file.datatype == 0) || (xcsv_file.datatype == wptdata)) {
+       if (global_opts.masked_objective & (TRKDATAMASK|RTEDATAMASK)) {
+           warning(MYNAME " attempt to read %s as a track or route, but this format only supports waypoints on read.  Reading as waypoints instead.\n", fname);
+       }
     }
 
     xcsv_file.xcsvfp = gbfopen(fname, "r", MYNAME);